import 'package:chop/common/StringUtils.dart';
import 'package:chop/view/home/place_an_order/Buying_order.dart';
//import 'package:chop/view/map/New_location.dart';
//import 'package:chop/view/sendyou/send_address_page.dart';
import 'package:chop/widgets/TextSizeWidget.dart';
import 'package:chop/widgets/ToastWidget.dart';
import 'package:chop/widgets/appBar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class Buying_job extends StatefulWidget {
  @override
  _Buying_jobState createState() => _Buying_jobState();
}

class _Buying_jobState extends State<Buying_job> {
  List<String> examples = [
    "填写例子1",
    "填写例子2",
    "填写例子3",
    "填写例子4",
    "填写例子5",
    "填写例子6",
    "填写例子7",
    "填写例子8",
  ];

  int example_index = 0;

  TextEditingController _commodity; //购买的商品

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _commodity = TextEditingController();
    money += choose;
  }

  int choose = 0; //商品种类附加价格
  int money = 12; //起步价
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: BaseViewBar(
          childView: BaseTitleBar("帮我买"),
          preferredSize: Size.fromHeight(50.0),
        ),
        body: Stack(
          children: <Widget>[
            Center(
              child: Container(
                  child: getColumn(
                "帮我买",
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    TextFormField(
                      maxLines: 4,
                      controller: _commodity,
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(30),
                        color: Colors.black,
                      ),
                      decoration: InputDecoration(
                          helperText: "请填写‘品牌’、‘数量’、‘规格’",
                          border: InputBorder.none),
                    ),
                    Container(
                      alignment: Alignment.topLeft,
                      child: GestureDetector(
                        child: FixedSizeText("填写示例"),
                        onTap: () {
                          _commodity.text = examples[example_index];
                          setState(() {
                            if (example_index == examples.length - 1) {
                              example_index = 0;
                            } else {
                              example_index++;
                            }
                          });
//                          showDialog<Null>(
//                            context: context, //BuildContext对象
//                            barrierDismissible: false,
//                            builder: (BuildContext context) {
//                              return showDia(
//                                //调用对话框
//                                text: '示例',
//                                child: Container(
//
//                                ),
//                              );
//                            },
//                          );
                        },
                      ),
                    )
                  ],
                ),
              )),
            ),
            Positioned(
              bottom: 0,
              width: MediaQuery.of(context).size.width,
              height: 70,
              child: Container(
                  padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
                  width: double.infinity,
//                height: 80,
//                      height: double.infinity,
                  color: Colors.white,
                  child: Center(
                    child: RaisedButton(
                      //提交按钮
                      color: Colors.lightBlueAccent,
                      highlightColor: Colors.blueAccent,
                      splashColor: Colors.blue,
                      colorBrightness: Brightness.dark,
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(10)),
                      onPressed: () async {
                        if (StringUtils.isNull(_commodity.text.trim())) {
                          Toast.toast(context, msg: "请填写需要购买的商品");
                        } else {
                          Get.to(Buy_order(
                            commodity: _commodity.text.trim(),
                          ));
                        }
//                          showDialog<Null>(
//                            context: context, //BuildContext对象
//                            barrierDismissible: false,
//                            builder: (BuildContext context) {
//                              return LoadingDialog(
//                                //调用对话框
//                                text: '请稍后...',
//                              );
//                            },
//                          );
//                          orderData data = orderData();
//                          data.begin = "${begin.address} ${begin.remark}";
//                          data.end = "${end.address} ${end.remark}";
//                          data.endName = end.name;
//                          data.distance = double.parse(range);
//                          data.money = price;
//                          data.beginLat = begin.lat;
//                          data.beginLng = begin.lng;
//                          data.endLng = end.lng;
//                          data.endLat = end.lat;
//                          data.fromId = int.parse(await SPUtils.get("UID"));
//                          data.fromName = begin.name;
//                          data.orderType = "1";
//                          data.status = "2";
//                          data.remark = _remarks.text.trim();
//                          await DioUtils.orderAdd(data)
//                              .then((OrderEntity orderEntity) {
//                            Get.back();
//                            if (orderEntity.code == 500) {
//                              Toast.toast(context,
//                                  msg: "请稍后重试", bgColor: Colors.redAccent);
//                              print("发起订单发生错误： ${orderEntity.msg}");
//                            } else if (orderEntity.code == 0) {
//                              Get.to(PayList(
//                                orderdata: orderEntity.data,
//                              ));
//                            } else {
//                              Toast.toast(context,
//                                  msg: "发生未知原因错误",
//                                  bgColor: Colors.redAccent);
//                            }
//                          });
//                              Get.to(PayList());
                      },
                      child: FixedSizeText(
                        '去下单',
                        style: TextStyle(color: Colors.white, fontSize: 15),
                      ),
                    ),
                  )),
            )
          ],
        ));
  }
}
